<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>医生列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/jquery.min.js"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">

                            <form class="layui-form layui-col-space5" lay-filter="example">
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="tdepartmentsId" id="tdepartmentsId">
                                        <option value="0">请选择</option>
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="name" id="name" placeholder="请输医生名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="button" class="layui-btn layui-icon"  lay-submit="" lay-filter="sreach"  value=&#xe615;></input>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加医生','./doctor-add.html',900,830)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form layui-hide" id="test">

                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div> 
    </body>

    <script type="text/html" id="action">


            <a title="编辑" onclick="xadmin.open('编辑','doctor-view.html?id='+'{{d.doctorId}}',600,500)" href="javascript:;">
                <i class="layui-icon">&#xe63c;</i>
            </a>
            <a title="禁用" onclick="member_del(this,'{{d.doctorId}}')" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
            </a>

    </script>

    <script id="gender" type="text/html">
        {{# if(d.sex==0){ }}
        男
        {{# }else{ }}
        女
        {{# } }}
    </script>

    <script id="pic1" type="text/html">
        <img src="https://jt98-hospital.oss-cn-shenzhen.aliyuncs.com/{{d.pic}}" width="50" height="50">
    </script>

    <script>
        var token =  localStorage.getItem("token");
        var  head = new Headers();
        head.append('token',token);
        layui.use(['form','table'], function(){
            var table = layui.table;
            var form = layui.form;

            form.on('submit(sreach)', function(data){
                var name = $("#name").val();
                var tdepartmentsId = $("#tdepartmentsId").val();

                table.render({
                    elem: '#test'
                    ,url: '/hospital/api/back/doctor/limit' //数据接口
                    ,page: true //开启分页
                    ,limit:20
                    ,headers: {
                        'token':token
                    }
                    ,where: {"name":name,"tdepartmentsId":tdepartmentsId}
                    ,done:function () {//渲染完成后的回调

                    },parseData:function(res){
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list //解析数据列表
                        };

                    },response:{
                        statusCode:0
                    }
                    ,cols: [[ //表头
                        //,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                        {field: 'doctorId', title: 'ID', hide:true}
                        ,{field:'pic',title:'头像',templet:'#pic1'}
                        ,{field: 'name', title: '名称'}
                        ,{field: 'identity', title: '身份证'}
                        ,{field:'nation',title:'民族'}
                        ,{field:'sex',title:'性别',templet:'#gender'}
                        ,{field:'roleName',title:'角色'}
                        ,{field:'tdepartmentsName',title:'科室'}
                        ,{field:'phone',title:'电话'}
                        ,{fixed:'right',title:'操作',toolbar:'#action',class:"td-manage"}
                    ]]
                });
            });
        });

        /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }

          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要禁用吗？',function(index){
              //发异步删除数据
              $.ajax({
                  type:"get",
                  url:"/hospital/api/back/doctor/forbidden",
                  data:{"id": id,"forbidden":0
                  },
                  dataType:"json",
                  headers: {
                      'token':token
                  },
                  success:function(msg){
                      if(msg.code==0){
                          $(obj).parents("tr").remove();
                          layer.msg('已禁用!',{icon:1,time:1000});
                      }
                      else{
                          layer.msg("禁用失败！");
                      }

                  }
              });

          });
      }



      function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

    <script>
        $(function () {
            $.ajax({
                type:"post",
                url:"/hospital/api/back/departments/getTdepartments",
                dataType:"json",
                async: false,
                headers: {
                    'token':token
                },
                success:function(msg){
                    var user= msg.data;
                    for(var i = 0;i<user.length;i++){
                        //alert(user[i].tdepartmentsId+user[i].tdepartmentsName);
                        $("#tdepartmentsId").append("<option value="+user[i].tdepartmentsId+">"+user[i].tdepartmentsName+"</option>" );
                    }
                }
            });
        })


        layui.use(['layer', 'form','table'], function(){
            var table = layui.table;
            var form = layui.form;



            table.render({
                elem: '#test'
                ,url: '/hospital/api/back/doctor/limit' //数据接口
                ,page: true //开启分页
                ,limit:20
                ,headers: {
                    'token':token
                }
                ,done:function () {//渲染完成后的回调

                },parseData:function(res){
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };

                },response:{
                    statusCode:0
                }
                ,cols: [[ //表头
                    //,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                    {field: 'doctorId', title: 'ID', hide:true}
                    ,{field:'pic',title:'头像',templet:'#pic1'}
                    ,{field: 'name', title: '名称'}
                    ,{field: 'identity', title: '身份证'}
                    ,{field:'nation',title:'民族'}
                    ,{field:'sex',title:'性别',templet:'#gender'}
                    ,{field:'roleName',title:'角色'}
                    ,{field:'tdepartmentsName',title:'科室'}
                    ,{field:'phone',title:'电话'}
                    ,{fixed:'right',title:'操作',toolbar:'#action',class:"td-manage"}
                ]]
            });



            //监听table中的工具栏
            table.on('tool(test)',function(obj) {
                //console.log(obj);
                //console.log(obj.data)
                var data = obj.data;
                console.log(data);
                switch (obj.event) {
                    case  'del':
                        layer.confirm("确定要删除该用户吗?"+obj.data.euUserName,function (index) {
                            $.ajax({
                                url:"/ecbuy/sys/user/del.json",
                                type:"post",
                                dataType:"json",
                                data:{"id":data.euUserId},
                                success:function (msg) {
                                    //console.log("删除数据"+msg);
                                    layer.close(index);
                                    if(msg.code==20000){
                                        obj.del();
                                        layer.msg("删除成功！");
                                    }else {
                                        layer.msg("删除失败");
                                    }
                                }
                            });
                        });
                        break;
                }
            });

        });





    </script>


</html>